package com.wjk.StuManager.Service;

import com.wjk.StuManager.Dao.StuDao;
import com.wjk.StuManager.Domain.Student;

public class StuService {
    StuDao stuDao=new StuDao();
    public boolean addStu(Student stu) {
        return stuDao.addStu(stu);
    }

    public boolean isExists(String id) {
        Student[] stus= stuDao.findAllStu();
        boolean flag=false;
        for (int i = 0; i < stus.length; i++) {
            Student stu=stus[i];
            if (stu!=null&&stu.getId().equals(id)){
                flag=true;
            }
        }
        return flag;
    }

    public void delStuById(String delId) {
        stuDao.delStuById(delId);
    }

    public void updateStu(String updateId,Student stu) {
        stuDao.updateStu(updateId, stu);
    }

    public Student[] findAllStu() {
        Student[] stus= stuDao.findAllStu();
        boolean flag=false;
        for (int i = 0; i < stus.length; i++) {
            Student stu=stus[i];
            if (stu!=null){
                flag=true;
                break;
            }
        }
        if (flag){
            return stus;
        }else {
            return null;
        }
    }
}
